package com.sq108.template.web.controller;


import com.sq108.template.domain.User;
import com.sq108.template.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tc.app.base.model.RefResult;
import tc.app.base.model.States;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户接口
 *
 * @author liulei
 */
@RestController
@RequestMapping(value = "/template/user")
@Api(value = "template", description = "模板")
public class UserController {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private UserService userService;


    @ApiOperation(value = "获取用户基本信息", response = RefResult.class)
    @RequestMapping(value = "/{userId}", method = {RequestMethod.GET})
    public RefResult<User> getUser(HttpServletRequest request, @PathVariable("userId") Integer userId) {
        try {
            User user = userService.getUser(userId);
            logger.info("测试日志输出");
            return new RefResult<>(States.Success, user);

        } catch (Exception ex) {
            logger.error("getUser(" + userId + ")", ex);
            return new RefResult<>(States.Exception);
        }
    }
}
